/*
 * PhoneDict: A J2ME Dict client
 * 
 * Copyright (C) 2006 Labeneator labeneator@gmail.org
 *
 * This file is a part of PhoneDict. PhoneDict is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the Free 
 * Software Foundation; either version 2 of the License, or (at your option) any later version.
 * Mobber is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 */

package dict;

import java.io.*;

public class DictAsk extends OutputStreamWriter {
	
	StringBuffer response = new StringBuffer();
	String defnTerm =  "\r\n.\r\n250";
	public static final String version = "0.1";

	 public DictAsk (OutputStream out) throws IOException, UnsupportedEncodingException
     {
             super(out);
             tellUA();
     }
	public void askDefination(String word, String dict) throws IOException
	{
		String question =  "DEFINE "+dict+" "+word+"\r\n";
		write(question);
		super.flush();		
	}
	public void askMatch(String word, String dict, String strategy) throws IOException
	{
		String question =  "MATCH "+dict+" "+strategy+" "+word+"\r\n";
		write(question);
		super.flush();		
	}
	public void askWords(String word, String dict, String strategy) throws IOException
	{
		String question =  "MATCH "+dict+" "+strategy+" "+word+"\r\n";
		write(question);
		super.flush();		
	}
	public void askDatabases() throws IOException
	{
		String question =  "SHOW DATABASES\r\n";
		write(question);
		super.flush();		
	}
	public void askServerStatus() throws IOException
	{
		String question =  "STATUS\r\n";
		write(question);
		super.flush();		
	}
	public void askServerHelp() throws IOException
	{
		String question =  "HELP\r\n";
		write(question);
		super.flush();		
	}
	public void askStrategy() throws IOException
	{
		String question =  "SHOW STRAT\r\n";
		write(question);
		super.flush();		
	}
	public void askDatabaseInfo(String dict) throws IOException
	{
		String question =  "SHOW INFO "+dict+"\r\n";
		write(question);
		super.flush();		
	}
	public void askServer() throws IOException
	{
		String question =  "SHOW SERVER\r\n";
		write(question);
		super.flush();		
	}
	public void tellUA() throws IOException
	{
		String ua =  "CLIENT PhoneDict/"+ version +" "+System.getProperty("microedition.platform")+"\r\n";
		System.out.println(ua);
		write(ua);
		super.flush();		
	}

}
